import time

from Common.Base import Base, open_browser

register_url = "http://localhost:8080/ecshop/user.php?act=register"


class RegisterPage(Base):
    # 表现层
    username_rec = ("name", "username")
    email_rec = ("name", "email")
    password_rec = ("name", "password")
    confirm_password_rec = ("name", "confirm_password")
    extend_field5_rec = ("name", "extend_field5")
    click_register_rec = ("name", "Submit")

    # 操作层
    def input_username(self, username):
        self.send_keys(self.username_rec, username)

    def input_email(self, email):
        self.send_keys(self.email_rec, email)

    def input_password(self, password):
        self.send_keys(self.password_rec, password)

    def input_confirm_password(self, confirm_password):
        self.send_keys(self.confirm_password_rec, confirm_password)

    def input_extend_field5(self, extend_field5):
        self.send_keys(self.extend_field5_rec, extend_field5)

    def click_register(self):
        self.click(self.click_register_rec)


if __name__ == '__main__':
    driver = open_browser()
    rec = RegisterPage(driver)
    rec.open_url(register_url)
    rec.input_username("iu123456")
    rec.input_email("123456@163.com")
    rec.input_password("Aa112211")
    rec.input_confirm_password("Aa112211")
    rec.input_extend_field5("17602368605")
    rec.click_register()
    time.sleep(5)
    rec.close_browser()
